<%@ page import="org.cscarioni.Sprint" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Sprint Panel</title>
        <g:javascript library="jquery"/>
        <g:javascript  src="jquery/jquery.jcontext.1.0.js"/>
        <g:javascript  src="jquery/jquery.jqmodal.js"/>
        <g:javascript  src="jquery/jquery.form.js"/>
        <g:javascript  src="jquery/jquery-ui-1.7.2.custom.min.js"/>
        <link rel="stylesheet" href="${resource(dir:'css',file:'contextmenu.css')}" />  
        <link rel="stylesheet" href="${resource(dir:'css',file:'jqmodal.css')}" /> 
        <link rel="stylesheet" href="${resource(dir:'css/ui-lightness',file:'jquery-ui-1.7.2.custom.css')}" /> 
        <style>
			@media print
			 {
			     #panelDiv{display:none;}
			 	 #graphHolder{display:block;}
			 	 #upperOptions{display:none;}
			 	 #menu{display:none;}
			 	 #estimadasRestantes{display:none;}
			 }
			
		 </style>            
     <script>
     $(function(){
		 var onDropCardInColumn=function(event,ui){
				var cardID=ui.draggable.find(".cardID").text();
				var columnID=$(this).attr("title");
				$.ajax({
					   type: "POST",
					   url: "<g:createLink controller='card' action='changeColumn' />",
					   data: "cardID="+cardID+"&columnID="+columnID,
					 });
									
	      }
    	 $("#cardHolder").jqm({modal:true,zIndex: 500});  
    	 $("#graphHolder").jqm({modal:true,zIndex: 700});  
    	 $(".smallcard").draggable({containment: 'document',scroll: false, opacity: 0.35 , revert: 'invalid' }); 	
    	 $(".panelcolumn").droppable({accept:'.smallcard', tolerance: 'fit' ,hoverClass: 'panelcolumndrophover' , drop: onDropCardInColumn});
    	 $(".smallcard").dblclick(function(){
        	 var cardId=$(this).find(".cardID").text();
			$.get("<g:createLink controller='card' action='modify' />",{cardID: cardId},function(data){
				     $("#cardHolder").html(data);
				     showCardModal();
			       }
			 );
	      }); 
     });
    function showCardModal(){		
		$("#cardHolder").jqmShow();
		$("#cardHolder").show();
     }
    function showGraphModal(){		
		$("#graphHolder").jqmShow();
		$("#graphHolder").show();
     }
    function callbackCardCreated(){
    	$("#cardHolder").jqmHide();
    	window.location="<g:createLink controller='sprint' action='showPanelForSprint' params='[sprintId:sprint.id,userId:user?.id]'/>";
    }

    function closeChartCallBack(){
    	$("#graphHolder").jqmHide();
    }
    </script>
    
    </head>
   
    <body>
    	<div id="upperOptions">
    	<div>
    		<g:remoteLink onComplete="showGraphModal();" class="create" action="createChart" controller="chart" params="[entity:'Sprint',sprintId:sprint.id,entityId:sprint.id,propertyName:'estimatedTimes']" update="graphHolder">Show Chart</g:remoteLink>
    	</div>	
    	<div style="display: none;">
    		<g:link class="create" action="goToEstimatesSavingPage" controller="estimates" params="[sprintId:sprint.id]">Save estimates</g:link>
    	</div>
		<div>
    		<g:link class="create" action="tableView" controller="sprint" params="[sprintId:sprint.id]">Show Table View</g:link>
    	</div>
    	<div style="width: 100%">
    		${sprint}
    	</div>
    	<div class="formDiv">
    		<g:form name="filterForm" action="showPanelForSprint">
    		 <g:ifAnyGranted role="ROLE_ADMINISTRATOR">  
    		  <g:select name="userId" from="${org.cscarioni.User.list()}" optionKey="id" noSelection="${['-1':'-- no selection --']}" value="${user?.id}"/>    		 
    		 </g:ifAnyGranted>
    		 <g:ifAnyGranted role="ROLE_USER">
    		  <g:ifNotGranted role="ROLE_ADMINISTRATOR">  
    		    <g:textField name="userName" value="${user?.username}" readonly="true"/>
    		    <g:hiddenField name="userId" value="${user?.id}"/>
    		  </g:ifNotGranted>
    		 </g:ifAnyGranted>
    		 <g:hiddenField name="sprintId" value="${sprint.id}"/>
    		 <g:submitButton value="Filter" name="filter"/>
    		 </g:form>
    	</div>
    	</div>
    	<div style="width: 100%;" id="panelDiv">
    	<g:each in="${sprint.panel.columns}">
    		<div id="column${it.id}" class="panelcolumn" title="${it.id}">
    		<div class="columnTitle">
    			${it.name}
    		</div>
    		<script language="javascript" type="text/javascript">
       			 $(function(){
           			 $("#column"+${it.id}).showMenu({
           				opacity:0.8,
           				query: ".contextmenu"
           			});            		
            			       		           			 
       			 });
       			 
       		 </script>
       		     <%
					def totalRestantes=0;
					def totalEstimadas=0;
				%>
       		 <div class="minicardcollection">	    
       		 	<g:each in="${it.cards}" var="card">
       		 		<g:if test="${!user || card.user == user}">       		 		
       		 		<g:smallcard card="${card}"/>
       		 		<%totalEstimadas=totalEstimadas+card?.estimatedTime%>
       		 		<%totalRestantes=totalRestantes+card?.remainingTime%>
       		 		</g:if>
       		 	</g:each>
       		 </div>
       		</div> 
    	</g:each>
    	</div>
    	<div style="display: none;" class="contextmenu">
  			 <ul>
  				 <li><g:remoteLink  onComplete="showCardModal();" controller="card" action="create" params="[sprintId:sprint.id]" update="cardHolder" >Add Task</g:remoteLink></li>
  				 <li><a href="#">Order By Sprint</a></li>
   			</ul>
		</div>
    	<div id="cardHolder" class="jqmWindow">
    	</div>    
    	<div id="graphHolder" class="jqmWindow" style="width:800px;" >
    	</div> 	
    </body>
</html>    